home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / OS2 / CFGED.ARJ / LBMAIN.CC < prev    next >
C/C++ Source or Header  |  1992-07-18  |  9KB  |  306 lines

  1. // this might look like 'C', but it's really  -*-c++-*-
  2. /* lbmain.cc
  3.  *
  4.  * Implementation of class MainBrowserDlg for CFGED
  5.  *
  6.  * Language        : C++
  7.  * Operating System: OS/2 V2.0 and higher
  8.  * Compiler        : GNU GCC V2.1 and higher
  9.  *
  10.  *
  11.  * $Id: lbmain.cc,v 1.1 1992/07/17 00:23:31 gruen Exp $
  12.  * $Log: lbmain.cc,v $
  13. // Revision 1.1  1992/07/17  00:23:31  gruen
  14. // Initial revision
  15. //
  16.  *
  17.  * Copyright (c) 1992 Lutz Grueneberg
  18.  *
  19.  * This library is free software; you can redistribute it and/or modify
  20.  * it under the terms of the GNU Library General Public License as
  21.  * published by the Free Software Foundation; either version 2 of the
  22.  * License, or (at your option) any later version.  This library is
  23.  * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  24.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  25.  * A PARTICULAR PURPOSE.  See the GNU Library General Public License for
  26.  * more details. You should have received a copy of the GNU Library
  27.  * General Public License along with this library; if not, write to the
  28.  * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  29.  */
  30. #define INCL_PM
  31. #include <os2.h>
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <unistd.h>
  35. #include <pmviews/pmviews.h>
  36. #include "cfgfile.h"
  37. #include "lbmain.h"
  38. #include "maindlg.h"
  39. #include "prompter.h"
  40. #include "pmctool.h"
  41. #include "sbrowser.h"
  42.  
  43.      MainBrowserDlg::MainBrowserDlg( StdWindow *pStdWindow, 
  44.                     USHORT  idResNew,
  45.                                     HWND hwndParentNew=HWND_DESKTOP)
  46. :( pStdWindow, idResNew, hwndParentNew) {
  47.           
  48.   plbMain = new ListBox( this, MAIN_LB);
  49.   pbtEdit   = new CntrlWindow( this, EDIT_BUTT);
  50.   pbtBrowse = new CntrlWindow( this, BROWSE_BUTT);
  51.   pbtInsert = new CntrlWindow( this, INSERT_BUTT);
  52.   pbtAppend = new CntrlWindow( this, APPEND_BUTT);
  53.   pbtDelete = new CntrlWindow( this, DELETE_BUTT);
  54.   pLdCfgDlg = NULL;
  55. }
  56.  
  57. VOID MainBrowserDlg::setState( int stateNew) {
  58.   switch( stateNew) {
  59.   case 0:     
  60.     plbMain->enable( TRUE);
  61.     pbtEdit->enable( FALSE);
  62.     pbtBrowse->enable( FALSE);
  63.     pbtInsert->enable( FALSE);
  64.     pbtAppend->enable( FALSE);
  65.     pbtDelete->enable( FALSE);
  66.     break;
  67.  
  68.   case 1:
  69.     plbMain->enable( TRUE);
  70.     pbtEdit->enable( TRUE);
  71.     pbtBrowse->enable( TRUE);
  72.     pbtInsert->enable( TRUE);
  73.     pbtAppend->enable( TRUE);
  74.     pbtDelete->enable( TRUE);
  75.     break;
  76.   }
  77. }
  78.  
  79. VOID MainBrowserDlg::loadCfgList( VOID){
  80.   /* query the right CONFIG.SYS */
  81.   if( !pLdCfgDlg) 
  82.     pLdCfgDlg = new LoadConfigDlg( queryOwnerWindow(), LDCFG_DLG);
  83.   pLdCfgDlg->create();
  84.   /* read the CONFIG.SYS */
  85.   cfile.read( (char*)(*(pLdCfgDlg->pSelected)));
  86.   cfile.printToListBox( plbMain);
  87.   setState(0);
  88. }
  89.  
  90. VOID MainBrowserDlg::saveCfgList( VOID){
  91.   CHAR   szBuf[300];
  92.   String str("c:\\config.old");
  93.  
  94.   sprintf( szBuf, "%s%s%s%s",
  95.       "Do you really want to save the actual configuration ",
  96.       "to the file '",
  97.       (char*)(*(pLdCfgDlg->pSelected)),
  98.       "'?");
  99.   if( PmUserRequest( HWND_DESKTOP, szBuf)) {
  100.     str[0] = (*(pLdCfgDlg->pSelected))[0];
  101.     cfile.save( (char*)(*(pLdCfgDlg->pSelected)), (char*)str);
  102.     sprintf( szBuf, "%s%s%s%s%s%s", 
  103.         "The actual configuration was stored to the file '",
  104.         (char*)(*(pLdCfgDlg->pSelected)),
  105.         "'.\nThe old configuration was saved to the file '",
  106.         (char*)str,
  107.             "'.\nThe changed version of the configuration takes",
  108.         "affect after the next shutdown!");
  109.     PmUserMessage( HWND_DESKTOP, szBuf);
  110.   }
  111.  
  112.   cfile.printToListBox( plbMain);
  113.   setState(0);
  114. }
  115.  
  116. VOID MainBrowserDlg::editEntry( VOID)
  117. { SHORT iSelect;
  118.   SHORT iTopIndex;
  119.   
  120.   PrompterDlg Prompter( queryOwnerWindow(), PR_DLG);
  121.   String test = "Hallo";
  122.   CHAR   *szComment="Edit the line, press OK to accept the change.";
  123.   iTopIndex = plbMain->queryTopIndex();
  124.   // find the selected line
  125.   Prompter.setString
  126.     (cfile.retrieve(iSelect=plbMain->querySelection( LIT_NONE)));
  127.   Prompter.setComment( szComment);
  128.   Prompter.create();
  129.   cfile.printToListBox( plbMain);
  130.   plbMain->setTopIndex( iTopIndex);
  131.   plbMain->selectItem( iSelect, TRUE);
  132.   setState( 1);
  133. }
  134.  
  135.  
  136. VOID MainBrowserDlg::browseEntry( SHORT iItem)
  137. { String    *pString;
  138.   StrDLList strList;
  139.   String    strgComment;
  140.   String    strgRemainer;
  141.   String*   pstrgTemp;
  142.   BOOL      fSemicolon = FALSE;
  143.  
  144.   // build list
  145.   pString = cfile.retrieve( iItem);
  146.   // verify browsability
  147.   if( !pString->contains( "=")) {
  148.     PmUserMessage( HWND_DESKTOP, 
  149.           "This entry can't be browsed.\nUse EDIT instead!");
  150.     return;
  151.   }
  152.   strgComment  = pString->before( "=");
  153.   strgRemainer = pString->after( "=");
  154.   while( strgRemainer.contains( ";")){
  155.     pstrgTemp = new String( strgRemainer.before( ";"));
  156.     strList.append( *pstrgTemp);
  157.     strgRemainer = strgRemainer.after( ";");
  158.   }
  159.   if( strgRemainer.length()) {
  160.     pstrgTemp = new String( strgRemainer);
  161.     strList.append( *pstrgTemp);
  162.   }
  163.   else fSemicolon = TRUE;
  164.   // display Dialog
  165.   SingleBrowser sb( queryOwnerWindow(), SB_DLG, "SingleBrowser",
  166.            (char*)strgComment, &strList);
  167.   sb.create();
  168.   // assemble string
  169.   *pString = strgComment;
  170.   *pString += "=";
  171.   for(Pix i = strList.first();
  172.       i != 0;
  173.       strList.next(i)) {
  174.     if( i != strList.first()) *pString += ";";
  175.     *pString += strList(i);
  176.   }
  177.   if( fSemicolon) *pString+=';';
  178. }
  179.     
  180. MRESULT MainBrowserDlg::msgInitDlg( HWND hwnd, USHORT msg, 
  181.                    MPARAM mp1, MPARAM mp2, BOOL *fDoDefault) {
  182.   SIZEL     sizl;
  183.   POINTL    ptl = {0,0};
  184.   StdWindow *pSW;
  185.   
  186.   /* SetUp the position */
  187.   pSW = queryOwnerWindow();
  188.   pSW->show( TRUE);        // display the complete window
  189.   querySize( &sizl);
  190.   pSW->setClientSize( &sizl);
  191.   setPos( &ptl);
  192.   pSW->setFramePos( &ptl);
  193.   /* loadCfgList to ListBox */
  194.   loadCfgList();
  195.   return 0;
  196. }
  197.  
  198. MRESULT MainBrowserDlg::msgControl( HWND hwnd, USHORT msg, 
  199.                    MPARAM mp1, MPARAM mp2, BOOL *fDoDefault) {
  200.   USHORT usID;
  201.  
  202.   usID = SHORT1FROMMP(mp1);
  203.  
  204.   switch (SHORT2FROMMP(mp1)) {   
  205.   case LN_ENTER:  /* Auswahl eines Item oder Double-Click */
  206.     editEntry();
  207.     *fDoDefault = FALSE;
  208.     return 0;
  209.  
  210.   case LN_SELECT: /* selection of a item of the list */
  211.     setState( 1);
  212.     *fDoDefault = 0;
  213.     return 0;
  214.   }
  215.   return 0;
  216. }
  217.  
  218. // this method reacts on the click to buttons
  219. MRESULT MainBrowserDlg::msgCommand( HWND hwnd, USHORT msg, 
  220.                    MPARAM mp1, MPARAM mp2, BOOL *fDoDefault) {
  221.   if( SHORT1FROMMP( mp2) == CMDSRC_PUSHBUTTON) {   
  222.     switch (SHORT1FROMMP(mp1)) {   
  223.     case EDIT_BUTT:        // OK Button Pressed
  224.       editEntry();
  225.       *fDoDefault = FALSE;
  226.       return 0;               
  227.    
  228.     case BROWSE_BUTT:        // OK Button Pressed
  229.       { SHORT iSelect;
  230.     SHORT iTopIndex;
  231.  
  232.     iTopIndex = plbMain->queryTopIndex();
  233.     browseEntry( iSelect = plbMain->querySelection( LIT_NONE));
  234.     cfile.printToListBox( plbMain);
  235.     plbMain->setTopIndex( iTopIndex);
  236.     plbMain->selectItem( iSelect, TRUE);
  237.     setState(1);
  238.       }
  239.       *fDoDefault = FALSE;
  240.       return 0;
  241.  
  242.     case INSERT_BUTT:        // INSERT Button pressed
  243.       {    PrompterDlg Prompter( queryOwnerWindow(), PR_DLG);
  244.     SHORT i = plbMain->querySelection( LIT_NONE);// retrieve active Element
  245.     String strNew = "";
  246.     Prompter.setString( &strNew);
  247.     Prompter.setComment( "Enter new property:");
  248.     Prompter.create();
  249.     if( strNew.length()){
  250.       String *pStrg = new String( strNew);
  251.       cfile.strList.ins_before( (Pix)(cfile.retrievePix( i)), *pStrg);
  252.     }
  253.     SHORT j = plbMain->queryTopIndex();
  254.     cfile.printToListBox( plbMain);
  255.     plbMain->setTopIndex(j);
  256.     plbMain->selectItem( i, TRUE);
  257.       }
  258.       *fDoDefault = FALSE;
  259.       return 0;
  260.  
  261.     case APPEND_BUTT:
  262.       // First this was implemented as an append at the end of the list.
  263.       // But this wasn't intuitive and so I've changed it. Now append means
  264.       // an insertion of an item after the actual one.
  265.       {    PrompterDlg Prompter( queryOwnerWindow(), PR_DLG);
  266.     SHORT i = plbMain->querySelection( LIT_NONE);// retrieve active Element
  267.     String strNew = "";
  268.     Prompter.setString( &strNew);
  269.     Prompter.setComment( "Enter new property:");
  270.     Prompter.create();
  271.     if( strNew.length()){
  272.       String *pStrg = new String( strNew);
  273.       cfile.strList.ins_after( (Pix)(cfile.retrievePix( i)), *pStrg);
  274.       SHORT j = plbMain->queryTopIndex();
  275.       cfile.printToListBox( plbMain);
  276.       plbMain->setTopIndex(j);
  277.       plbMain->selectItem( i+1, TRUE);
  278.     } else {
  279.       SHORT j = plbMain->queryTopIndex();
  280.       cfile.printToListBox( plbMain);
  281.       plbMain->setTopIndex(j);
  282.       plbMain->selectItem( i, TRUE);
  283.     }
  284.       }
  285.       *fDoDefault = FALSE;
  286.       return 0;
  287.  
  288.     case DELETE_BUTT:
  289.       {    SHORT iTopIndex;
  290.  
  291.     iTopIndex = plbMain->queryTopIndex();
  292.     SHORT i = plbMain->querySelection( LIT_NONE); // retrieve active
  293.     Pix p = i ? (Pix)cfile.retrievePix(i-1) : NULL;
  294.     cfile.strList.del_after( p);
  295.     cfile.printToListBox( plbMain);
  296.     plbMain->setTopIndex( iTopIndex);
  297.     setState(0);
  298.       }
  299.       *fDoDefault = FALSE;
  300.       return 0;
  301.     }
  302.   }
  303.   return 0;
  304. }
  305.  
  306.